<template>
  <el-dialog
    title="题目详情"
    :visible.sync="selfVisible"
    custom-class="question-preview"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
  >
    <div class="container">
      <QuestionList :questionList="questionList"></QuestionList>
    </div>
  </el-dialog>
</template>

<script>
import QuestionList from "./question-list.vue";
import { getTopicListByGaugetId } from "@/api/scale";

export default {
  name: "QuestionPreview",
  components: { QuestionList },
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    gaugeId: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      questionList: []
    };
  },
  computed: {
    selfVisible: {
      get() {
        return this.visible;
      },
      set(val) {
        this.$emit("update:visible", val);
      }
    }
  },
  watch: {
    gaugeId: {
      handler() {
        this.onLoad();
      },
      immediate: true
    }
  },
  methods: {
    async onLoad() {
      const { gaugeId } = this;
      if (!gaugeId) {
        return;
      }
      const { data } = await getTopicListByGaugetId({ gaugeId: gaugeId });
      this.questionList = data.data;
    }
  }
};
</script>

<style lang="scss" scoped>
.question-preview {
  .container {
    height: 60vh;
    overflow-y: auto;
  }
}
</style>
